package com.lune.blog.system.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lune.blog.base.domain.system.SysUser;
import com.lune.blog.base.domain.system.SysUserRole;
import com.lune.blog.system.mapper.UserRoleMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author yanjizhw@163.com
 * @date 2021/11/18 20:46
 * 描述:
 * @since 1.0.0
 */
@Service("userRoleService")
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, SysUserRole> {

    /**
     * 用户-角色关联表中获取角色ids
     * @param userId 用户id
     * @return 角色ids
     */
    public List<Long> getRoleIdsByUserId(Long userId) {
        return baseMapper.selectList(new QueryWrapper<SysUserRole>().eq("user_id", userId))
                .stream().map(SysUserRole::getRoleId).collect(Collectors.toList());
    }
}
